<template>
<!--	<div class="loginWrap">-->
<!--        <span class="pagetitle pageCover">loginWrap</span>-->
<!--	</div>-->

  <van-form @submit="handleLogin">
    <van-cell-group inset>
      <van-field v-model="loginForm.username" name="username" label="用户名" placeholder="用户名" :rules="[{ required: true, message: '请填写用户名' }]" />
      <van-field v-model="loginForm.password" type="password" name="password" label="密码" placeholder="密码" :rules="[{ required: true, message: '请填写密码' }]" />
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit"> 提交 </van-button>
    </div>
  </van-form>
</template>
<script setup>
	import eFlyLogin from '../service/login'
  import userStore from '../store/user'
  import { ref } from 'vue'
  import {useRouter} from 'vue-router'
  const router = useRouter()
  const store = userStore()

  const loginForm = ref({username:"", password:""})
	const handleLogin = async (params) => {
    console.log(params)
    eFlyLogin.login(params).then((loginResult) => {
      if (loginResult.data.code == 500) {
        message.warn(loginResult.data.msg)
      } else {
        const userinfo = loginResult.data.data
        store.saveUserInfo(userinfo.userId, userinfo.accessToken, userinfo.refreshToken)
        router.push({ path: '/' })
      }
    })
  }

</script>
<style type="text/css" lang="less" scoped>
	.loginWrap{
		.pagetitle{
			color:red;
		}
	}
</style>